<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>POS收单运营管理平台</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link href="<s:url value="/css/a.css"/>" type="text/css"
	rel="stylesheet" />
<link href="<s:url value="/css/index.css"/>" type="text/css"
	rel="stylesheet" />
	
<script type="text/javascript" src="<s:url value="/js/jquery-1.3.2.js" />"></script>
<script type='text/javascript' src='<s:url value="/dwr/engine.js"/>'></script>
<script type="text/javascript" src="<s:url value="/dwr/interface/AddressQuery.js"/>"></script>		
	
<script type="text/javascript">

$(document).ready(function() {
 loadSorts();
});

//清空显示选择提示
 function clearSelect(sid) {
			$("#" + sid).empty().append("<option value=''>--请选择--</option>");
 }
		
 //进行遍历存值
 function fillSelect_sort(sid, address) {
 		
		if (!address || !sid) {
			return;
		}
		var $select = $("#" + sid);
		$select.empty();
		if (address.length != 1) {
			$select.append("<option value=''>--请选择--</option>");
		}
		
		for ( var i = 0; i < address.length; i++) {
			$select.append("<option value='"+address[i].CODE+"'>"
					+ address[i].NAME + "</option>");
			
		}
		
		//如果是选择的银行下只有一个开户行明细,则直接赋值
		if(address.length == 1 && sid == "bankBranchs"){
		  accBackName();
		}
		
}


//加载一级类别  初始值主函数
function loadSorts() {
    
	AddressQuery.loadProvices(function(objs){
	
	clearSelect("citys");
	clearSelect("bankBranchs");
	fillSelect_sort("provinces", objs);
	loadCity();
	});
}

//load　　city
 function loadCity() {
	var sortCode = $("#provinces").val();
	$("#citys").val("");
	 $("#banks").val("");
	 $("bankBranchs").val("");
	if (!sortCode) {
		return;
	}
	AddressQuery.loadCitys(sortCode, function(sortSmall) {
		fillSelect_sort("citys", sortSmall);
	});
}

//load bank
  function loadBank(){
			 $("#banks").val("");
			 $("bankBranchs").val("");
		}
		
//load　bankBranch
 function loadBankBranch() {
	var b = $("#banks").val();
	var p=$("#provinces").val();
	var c=$("#citys").val();
	 $("bankBranchs").val("");
	if(p=="" || c==""){
		alert("请选择开户行所在地");
		return;
	}
	
	AddressQuery.loadPayBankBranch(b,p,c ,function(sortSmall) {
				fillSelect_sort("bankBranchs", sortSmall);
			});

   }
   
   //拼接开户行中文名称
   function accBackName(){
			var a= $("#banks  option:selected").text();
			var b= $("#bankBranchs  option:selected").text();
			
			var banks = $("#banks").val();
			
			if(banks=="313" || banks == "314"){
			 $("#accBack").val(b);
			}else{
			 $("#accBack").val(a+b);
			}
			
			
	}
   
   function choiseBank(){
    
    var bankBranchs = $("#bankBranchs").val();
    var accBack = $("#accBack").val();
    
  
    if(bankBranchs==null || bankBranchs ==""){
     alert("请选择开户行");
     return false;
    }
    
    var bankMes = accBack+"-"+bankBranchs;
    
    window.returnValue = bankMes;
    window.close();
   }
   
</script>    
</head>

<body>

		<form id="queryUserForm"  method="post" >
			
          <table width="100%" border="1" cellspacing="0" class="table">
          <tr>
          <td align="center" colspan="4">
	          <h2 class="headline-inquires">
						开户行选择<br />
			 <span class="sub-title"></span>
			 </h2>
		   </td>
          </tr>
          
          <tr>
             <td rowspan="2" width="40%">
                                  开户行所在地
             </td>
	          <td>
	            <select id="provinces" name="provinces"  onchange="loadCity()"  class="queryWidth"></select>
	          </td>
          </tr>
          
          <tr>
	        <td>
	            <select id="citys" name="citys" onchange="loadBank()" class="queryWidth"></select>
	        </td>
          </tr>
          
           <s:select id="banks" name="banks" list="#request.bankList"  onchange="loadBankBranch()"  listKey="key" listValue="value" headerKey="99" headerValue="--请选择--" cssClass="queryWidth"></s:select>
          
           <tr>
               <td>
                                      开户行名称
               </td>
           
	           <td>
	             <select id="bankBranchs"  name="merinfo.settBackId" class="queryWidth" onchange="accBackName()" ></select>
	             <s:hidden id ="accBack"></s:hidden>
	          </td>
          </tr>
          
			<tr>
			  <td colspan="4" align="center">
			   <input type="button" onclick="choiseBank();" value="确定" />
			  </td>
			</tr>
			
		 </table>
		</form>
</body>
</html>
